import pymysql


def main():
    # 创建connection链接
    conn = pymysql.connect(host="localhost",port=3306,database="jing_dong",user="root",password="mysql",charset="utf8")
    # 获取游标Cursor对象
    cur = conn.cursor()
    # 执行insert语句，并返回受影响的行数：添加一条数据
    count = cur.execute("insert into goods_cates(name) values('硬盘')")
    # 打印受影响的行
    print(count)

    count = cur.execute("insert into goods_cates(name) values('光盘')")
    print(count)

    # 提交之前的操作，如果之前已经之执行过多次的execute，那么就都进行提交
    conn.commit()

    # 关闭cursor对象
    cur.close()

    # 关闭connection链接对象
    conn.close()



if __name__ == "__main__":
    main()
